package com.yunquan.ohana.ui.mine

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import com.yunquan.ohana.BR
import com.yunquan.ohana.R
import com.yunquan.ohana.base.ui.BaseFragment
import com.yunquan.ohana.databinding.FragmentMineBinding
import com.yunquan.ohana.ui.mine.dialog.ContactsDialog

class MineFragment : BaseFragment<FragmentMineBinding, MineViewModel>() {

    companion object {
        fun newInstance(): MineFragment {
            return MineFragment()
        }
    }

    override fun initContentView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): Int {
        return R.layout.fragment_mine
    }

    override fun initVariableId(): Int {
        return BR.mineViewModel
    }

    override fun initData(savedInstanceState: Bundle?) {

    }

    override fun initViewObservable() {
        super.initViewObservable()
        viewModel!!.ui.observe(viewLifecycleOwner) { type ->
            when (type) {
                0 -> showContactsDialog()
            }
        }
    }

    private fun showContactsDialog() {
        val dialog = ContactsDialog(requireContext())
        dialog.setContacts(viewModel!!.contact.get())
        dialog.show()
    }
}